## 
## Copyright (C) 2008+ Spark Zheng
##
## dserver/test/Makefile
## Generate the unit test program.  
##

PREFIX		?= /home/sparkzheng/tools
PROJECT_HOME	?= /home/sparkzheng/code/dserver

CODE_TYPE       ?= c
CODE_VERSION    ?= alpha

export PREFIX
export PROJECT_HOME
export CODE_TYPE
export CODE_VERSION

CC			= gcc
CXX			= g++

CFLAGS		= -g -W -Wall -fPIC
CXXFLAGS	= -g -W -Wall -fPIC

CFLAGS_WARN	= -Wshadow -Wcast-qual -Wunreachable-code -Wredundant-decls \
			  -Wmissing-prototypes -Wstrict-prototypes -Wnested-externs -Winline
CXXFLAGS_WARN	= -Winline -Wunreachable-code -Winline -Wunreachable-code

CFLAGS_DEBUG	:= -D_DEBUG $(CFLAGS_WARN)
CXXFLAGS_DEBUG	:= -D_DEBUG $(CXXFLAGS_WARN)

CFLAGS_OPT		= -O2 -fomit-frame-pointer
CXXFLAGS_OPT	= -O2 -fomit-frame-pointer

INCFLAGS	:= -I. -I./include -I.. -I../include -I$(PREFIX)/include \
			   -I../src -I../src/include \
			   -I$(PROJECT_HOME) -I$(PROJECT_HOME)/include -I$(PROJECT_HOME)/src

LDFLAGS 	:= -Wl,-rpath,$(PROJECT_HOME) \
			   -Wl,-rpath,$(PROJECT_HOME)/src\
			   -Wl,-rpath,$(PREFIX)/lib \
			   -L. -L$(PROJECT_HOME) -L$(PROJECT_HOME)/src \
			   -L/usr/local/lib -L$(PREFIX)/lib
LIB_LDFLAGS	:= $(LDFLAGS) -Wl,-E -shared

LIBS 		= /home/sparkzheng/code/dserver/src/libdserver.a /home/sparkzheng/tools/lib/libdlib.a /usr/local/lib/libevent.a -lpthread -lrt
MC_LIBS		= $(LIBS)

RANLIB		= ranlib
AR			= ar
ARFLAGS		= ru

LD			= ld

INSTALL 	?= install -c
UNINSTALL	?= rm -f

DIRS		= 


TARGETS 	= $(EXEC_TARGETS) $(LIB_TARGETS)
EXEC_TARGETS	= $(SERVER_TARGETS) \
		  $(CLIENT_TARGETS) $(PRESS_TARGETS)
		  
LIB_TARGETS	= 
LIB_HEADS	= 
		  
SERVER_TARGETS	= ipserver
CLIENT_TARGETS	=
PRESS_TARGETS	=


OBJECTS		= $(EXEC_OBJECTS) $(LIB_OBJECTS)
EXEC_OBJECTS	= ipserver.o sgtree.o
		  
LIB_OBJECTS	= 


all: $(TARGETS)

ipserver: $(EXEC_OBJECTS)
	$(CC) -g -pg -o $@ $(EXEC_OBJECTS) $(LDFLAGS) $(LIBS)

.SUFFIXES:
.SUFFIXES:	.c .cpp .o

ifneq ("$(CODE_VERSION)","release")
.c.o :
	$(CC) -o $@ -c $< $(CFLAGS) $(CFLAGS_DEBUG) $(INCFLAGS)
.cpp.o :
	$(CXX) -o $@ -c $< $(CXXFLAGS) $(CXXFLAGS_DEBUG) $(INCFLAGS)
else
.c.o :
	$(CC) -o $@ -c $< $(CFLAGS) $(CFLAGS_OPT) $(INCFLAGS)
.cpp.o :
	$(CXX) -o $@ -c $< $(CXXFLAGS) $(CXXFLAGS_OPT) $(INCFLAGS)
endif


count:
	-wc *.c *.cc *.C *.cpp *.h *.hpp 2>/dev/null
	set -e; for i in $(DIRS); do \
		echo "make count enter $$i."; \
		make -C $$i count; \
		echo "make count leave $$i."; \
	done;

clean:
	-rm -f $(OBJECTS) *.swp *~ *.out core.* *.log $(TARGETS)
	set -e; for i in $(DIRS); do \
		echo "make clean enter $$i."; \
		make -C $$i clean; \
		echo "make clean leave $$i."; \
	done;


.PHONY: all
.PHONY: count
.PHONY: clean
.PHONY: cleanall
